package net.ikenway.springboot.demo.Config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Paths;

/**
 * @author MasterKenway <zk@ikenway.net>
 * @Description
 * @date Created Date 12/21/2020
 */
@Configuration
public class UploadConfigurer implements WebMvcConfigurer {
    @Value("${web.upload-path}")
    private String mImagesPath;

    @Value("${web.export-path}")
    private String exportPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/api/image/**").addResourceLocations("file:" + Paths.get(".").toAbsolutePath() + mImagesPath);
        registry.addResourceHandler("/api/excels/**").addResourceLocations("file:" + Paths.get(".").toAbsolutePath() + exportPath);
    }
}
